package 码云作业;
import java.io.*;
import java.util.Scanner;

public class text03 {
  
	 public static void copy(String pathname){
	        File inFile = new File(pathname);
	        File outFile =null;
	        if(inFile.exists()){
	            outFile = new File(inFile.getParentFile()+"/copy_"+inFile.getName());
	            try {
	                outFile.createNewFile();
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	        }
	        if(outFile!=null){
	            FileInputStream fis =null;
	            DataInputStream dis = null;
	            FileOutputStream fos=null;
	            DataOutputStream dos = null;
	            try {
	                fis = new FileInputStream(inFile);
	                dis=new DataInputStream(fis);
	                fos=new FileOutputStream(outFile);
	                dos=new DataOutputStream(fos);
	                int temp;
	                while ((temp=dis.read())!=-1){
	                    dos.write(temp);
	                }
	            }catch (IOException e){
	                e.printStackTrace();
	            }finally {
	                    try {
	                        if(fis!=null) {
	                            fis.close();
	                        }
	                        if(dis!=null){
	                            dis.close();
	                        }
	                        if(fos!=null){
	                            fos.close();
	                        }
	                        if(dos!=null){
	                            dos.close();
	                        }
	                    } catch (IOException e) {
	                        e.printStackTrace();
	                    }
	            }
	        }
	    }

	    public static void main(String[] args) {
	        Scanner input = new Scanner(System.in);
	        System.out.print("请输入文件名：");
	        String pathname = input.next();
	        copy(pathname);
	    }
}
